﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using WindowsInput.Native;
using WindowsInput;
using System.Runtime.InteropServices;
namespace ConsoleApp8
{




    internal class Program
    {

        [DllImport("user32.dll")]
        static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);


        [DllImport("user32.dll", EntryPoint = "mouse_event")]
        private static extern void MouseEvent(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
        static InputSimulator inputSimulator = new InputSimulator();

        static public void Add(Action<int> a)
        {
            a(10);
        }
        static Action<int> b { get; set; }
        static async Task Main(string[] args)
        {
            b = (a) =>
            {
                Console.WriteLine(a);
            };
         Add(a=> b(a));

            b(10);


            await Task.Delay(3000);
            List<string> passwords = GeneratePasswords();
            passwords = passwords.Skip(2000).ToList();
            Console.WriteLine($"共生成{passwords.Count}个密码:");
            foreach (string password in passwords)
            {
                await Console.Out.WriteLineAsync(password);
                foreach (var item in password)
                {
                    Send(int.Parse(item.ToString()));
                }
                await Task.Delay(100);
                await SimulateRETURN();
                await Task.Delay(200);
                SimulateLeftMouseClick();


                SimulateDelete();
                await Task.Delay(300);
            }

        }

        private const int MOUSEEVENTF_LEFTDOWN = 0x0002;
        private const int MOUSEEVENTF_LEFTUP = 0x0004;

        public static void SimulateLeftMouseClick()
        {
            // 模拟鼠标左键按下
            MouseEvent(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);

            // 模拟鼠标左键释放
            MouseEvent(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
        }
        public static void Send(int i)
        {
            inputSimulator.Keyboard.KeyPress((VirtualKeyCode)(i + 96));
        }

        public static void SimulateDelete()
        {
            for (int i = 0; i < 4; i++)
            {
                inputSimulator.Keyboard.KeyPress(VirtualKeyCode.BACK);
            }

        }
        public static async Task SimulateRETURN()
        {
            for (int i = 0; i < 3; i++)
            {
                if (i == 2)
                {
                    await Task.Delay(3000);
                }
                inputSimulator.Keyboard.KeyPress(VirtualKeyCode.RETURN);

            }

        }
        static List<string> GeneratePasswords()
        {
            List<string> passwords = new List<string>();
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        for (int l = 0; l < 10; l++)
                        {
                            string password = $"{i}{j}{k}{l}";
                            passwords.Add(password);
                        }
                    }
                }
            }
            return passwords;
        }
        public static List<string> GenerateFirstHalfPasswords()
        {
            List<string> passwords = new List<string>();
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        for (int l = 0; l < 5; l++)
                        {
                            string password = $"{i}{j}{k}{l}";
                            passwords.Add(password);
                        }
                    }
                }
            }
            return passwords;
        }
        public static List<string> GenerateSecondHalfPasswords()
        {
            List<string> passwords = new List<string>();
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        for (int l = 5; l < 10; l++)
                        {
                            string password = $"{i}{j}{k}{l}";
                            passwords.Add(password);
                        }
                    }
                }
            }
            return passwords;
        }
    }
}
